<#import "../tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="会员管理">
<style>
    .form-horizontal .controls {
        line-height: 40px;
        height: 40px;
        margin-left: 3px;
    }

    .button-primary {
        margin-left: -10px;
    }

    .button-danger {
        margin-left: -25px;
    }
</style>
<!--suppress ALL -->
<form id="searchForm" class="form-panel" action="${basepath}/rest/manage/account/loadAccountData">
    <ul class="panel-content">
        <li>
            <div class="control-group span5">
                <div class="search-controls  controls">
                    <input type="text" name="createTime" id="createTime" value="" placeholder="搜索关键字">
                </div>
            </div>
            <div class="form-actions span2">
                <button type="submit" class="button  button-primary">
                    搜索
                </button>
            </div>
        </li>
    </ul>
</form>
<div id="grid"></div>
<#----------------------------------------------查看消费详情表单start--------------------------------------------------------->
<div id="editContent" style="display:none;">
    <form id="editForm" class="form-horizontal">
        <div class="row">

            <div class="control-group span16">
                <label class="control-label">原会员等级：</label>

                <div class="control-group-img  controls ">
                    <input type="text" class="input-normal control-text" name="oldRank" disabled>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="control-group span16">
                <label class="control-label">现会员等级：</label>

                <div class="control-group-img  controls ">
                    <input type="text" class="input-normal control-text" name="nowRank" disabled>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">联系人姓名：</label>

                <div class="control-group-img  controls ">
                    <input type="text" class="input-normal control-text" name="contactName" disabled>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">联系电话：</label>

                <div class="control-group-img  controls ">
                    <input type="text" class="input-normal control-text" name="contactNumber" disabled>
                </div>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">赠送商品：</label>

            <div class="controls">
                <div id="p-product">
                    <input type="text" class="input-normal control-text" name="productName" disabled>
                </div>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">赠送规格：</label>

            <div class="controls">
                <div id="p-product">
                    <input type="text" class="input-normal control-text" name="specInfo" disabled>
                </div>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">赠送数量：</label>

            <div class="controls">
                <div id="p-product">
                    <input type="text" class="input-normal control-text" name="number" disabled>
                </div>
            </div>
        </div>
    </form>
</div>
<#----------------------------------------------查看消费详情表单end--------------------------------------------------------->
<#----------------------------------------------新增表单start--------------------------------------------------------->
<div id="addContent" style="display:none;">
    <form id="addForm" class="form-horizontal" action="${basepath}/rest/manage/order/updateCheckStatus" method="post">
        <input type="hidden" class="input-normal control-text" name="id"/>
        <input type="hidden" class="input-normal control-text" name="userID"/>
        <input type="hidden" class="input-normal control-text" name="rankType"/>
        <input type="hidden" class="input-normal control-text" name="productID"/>
        <input type="hidden" class="input-normal control-text" name="specInfo"/>
        <input type="hidden" class="input-normal control-text" name="price"/>
        <input type="hidden" class="input-normal control-text" name="number"/>
        <input type="hidden" class="input-normal control-text" name="ptotal"/>
        <input type="hidden" class="input-normal control-text" name="transType"/>

        <div class="row">
            <div class="control-group span16">
                <label class="control-label">开通等级：</label>

                <div class="controls control-row4">
                    <select data-rules="{required:true}" name="checkStatus">
                        <option value="">-请选择-</option>
                        <option value="pass">通过</option>
                        <option value="noPass">不通过</option>
                    </select>
                </div>
            </div>
        </div>
    </form>
</div>
<#----------------------------------------------新增表单 end---------------------------------------------------------->
<script>
    var Grid = BUI.Grid,
            Store = BUI.Data.Store,
            columns = [
                {title: '序号', dataIndex: 'id', elCls: 'center', width: '6%'},
                {title: '下单时间', dataIndex: 'createTime', elCls: 'center', width: '16%'},
                {title: '下单人', dataIndex: 'nickname', elCls: 'center', width: '16%'},
                {title: '购买会员等级', dataIndex: 'rankType', elCls: 'center', width: '11%'},
                {title: '消费金额', dataIndex: 'ptotal', elCls: 'center', width: '11%'},
                {
                    title: '支付方式', dataIndex: 'payType', elCls: 'center', width: '11%', renderer: function (value) {
                    if (value == "online") {
                        return "线上支付";
                    } else if (value == "offline") {
                        return "线下支付";
                    }
                }
                },
                {
                    title: '邀请金是否支出', dataIndex: 'id', elCls: 'center', width: '10%', renderer: function (value, obj) {
                    if (obj.affMoneyStatus == "unSend") {
                        return '<a href="javascript:invite(' + value + ')">未支出</a>';
                    } else {
                        return '已支出';
                    }

                }
                },
                {
                    title: '查看', dataIndex: 'id', elCls: 'center', width: '7%', renderer: function (value) {
                    return '<a href="javascript:detail(' + value + ')">查看</a>';
                }
                },
                {
                    title: '审批', dataIndex: 'checkStatus', elCls: 'center', width: '6%', renderer: function (value, obj) {
                    if (obj.payType == "online") {
                        return '——';
                    } else if (obj.payType == "offline") {
                        if(value=="pass"){
                            return '通过';
                        }else if(value=="noPass"){
                            return '不通过';
                        }else {
                            return '<a href="javascript:approved(' + obj.id + ')">操作</a>';
                        }

                    }
                }
                }
            ];

    var store = new Store({
                url: '/rest/manage/order/selectRankOrder',
                autoLoad: true, //自动加载数据
                params: { //配置初始请求的参数
                    length: '10'
                },
                pageSize: 10,	// 配置分页数目
                root: 'data',
                totalProperty: 'total'
            }),
            grid = new Grid.Grid({
                render: '#grid',
                width: '100%',//如果表格使用百分比，这个属性一定要设置
                columns: columns,
                loadMask: true, //加载数据时显示屏蔽层
                store: store,
                plugins: [Grid.Plugins.CheckSelection], // 插件形式引入多选表格
                // 底部工具栏
                bbar: {
                    pagingBar: true
                }
            }).render();

    /*--------------------------------模糊查询---------------------------------------------*/
    var form = new BUI.Form.HForm({
        srcNode: '#searchForm'
    }).render();

    form.on('beforesubmit', function (ev) {
        //序列化成对象
        var obj = form.serializeToObject();
        obj.start = 0; //返回第一页
        store.load(obj);
        return false;
    });
    /*--------------------------------模糊查询---------------------------------------------*/
    /*--------------------------------邀请是否支出---------------------------------------------*/

    function invite(value) {
        BUI.Message.Confirm('确定修改邀请奖金支出状态？', function () {
            $(".bui-stdmod-footer .button-primary").show();//确定
            $.ajax({
                type: 'POST',
                url: "${basepath}/rest/manage/order/updateJson",
                dataType: 'json',
                data: {
                    id: value,
                    affMoneyStatus: "send"
                },
                success: function () {
                    var obj = form.serializeToObject();
                    obj.start = 0; //返回第一页
                    store.load(obj);
                }
            });
        }, 'question');
    }
    /*--------------------------------邀请是否支出---------------------------------------------*/
    /*------------------------------------------------查看消费详情表单处理 start-----------------------------------------------*/
    var editForm = new BUI.Form.Form({
        srcNode: '#editForm',
        submitType: 'ajax',
        callback: function (data) {
            var obj = new Object();
            obj.start = 0; //返回第一页
            store.load(obj);
            editDialog.close();
        }
    }).render();

    var editDialog = new BUI.Overlay.Dialog({
        title: '查看消费详情',
        width: 500,
        height: 420,
        contentId: 'editContent',
        success: function () {

        }
    });

    //查看消费详情按钮事件
    function detail(value) {
        $.ajax({
            type: "GET",
            dataType: "json",
            url: "${basepath}/rest/manage/orderdetail/selectDetail",
            data: {
                orderID: value
            },
            success: function (data) {
                var form = $("#editForm")[0];
                BUI.FormHelper.setFields(form, data.data);
                editDialog.show();
                $(".bui-stdmod-footer .button-primary").hide();//确定隐藏
                $.ajax({
                    type: "GET",
                    dataType: "json",
                    url: "${basepath}/rest/manage/order/selectRankOrderDetail",
                    data: {
                        id: value
                    },
                    success: function (data) {
                        $("input[name='contactName']").val(data.data.contactName);//查询电话联系人
                        $("input[name='contactNumber']").val(data.data.contactNumber);//查询电话号码
                        $("input[name='oldRank']").val(data.data.oldRankType);
                        $("input[name='nowRank']").val(data.data.rankType);
                    }
                });

//                //判断原会员等级
//                switch (oldRankType) {
//                    case 0:
//                        $("input[name='oldRank']").val("普通会员");
//                        break;
//                    case 1:
//                        $("input[name='oldRank']").val("铜牌会员");
//                        break;
//                    case 2:
//                        $("input[name='oldRank']").val("银牌会员");
//                        break;
//                    case 3:
//                        $("input[name='oldRank']").val("金牌会员");
//                        break;
//                    case 4:
//                        $("input[name='oldRank']").val("铂金会员");
//                        break;
//                    case 5:
//                        $("input[name='oldRank']").val("钻石会员");
//                        break;
//                    case 6:
//                        $("input[name='oldRank']").val("至尊会员");
//                        break;
//                }
//                //判断现在会员等级
//                switch (rankType) {
//                    case 0:
//                        $("input[name='nowRank']").val("普通会员");
//                        break;
//                    case 1:
//                        $("input[name='nowRank']").val("铜牌会员");
//                        break;
//                    case 2:
//                        $("input[name='nowRank']").val("银牌会员");
//                        break;
//                    case 3:
//                        $("input[name='nowRank']").val("金牌会员");
//                        break;
//                    case 4:
//                        $("input[name='nowRank']").val("铂金会员");
//                        break;
//                    case 5:
//                        $("input[name='nowRank']").val("钻石会员");
//                        break;
//                    case 6:
//                        $("input[name='nowRank']").val("至尊会员");
//                        break;
//                }
            }
        });
    }
    /*------------------------------------------------查看消费详情表单处理 end------------------------------------------------*/
    /*--------------------------------审批线下支付的状态（通过与不通过）---------------------------------------------*/
    var addForm = new BUI.Form.Form({
        srcNode: '#addForm',
        submitType: 'ajax',
        callback: function (data) {
            var obj = new Object();
            obj.start = 0; //返回第一页
            store.load(obj);
            addDialog.close();
        }
    }).render();

    var addDialog = new BUI.Overlay.Dialog({
        title: '开通等级',
        width: 400,
        height: 150,
        contentId: 'addContent',
        success: function () {
            if (addForm.isValid()) {
                addForm.submit();
            } else {
                addForm.valid();
            }
        }
    });
    function approved(id) {
        $.ajax({
            type: "GET",
            dataType: "json",
            url: "${basepath}/rest/manage/order/selectDetail",
            data: {
                id: id
            },
            success: function (data) {
                addForm.clearFields();
                addForm.clearErrors();      //添加的时候原来的错误提示
                var obj = new Object();
                obj.start = 0;              //返回第一页
                addDialog.show();
                $(".bui-stdmod-footer .button-primary").show();//确定
                $("input[name='id']").val(data.data.id);
                $("input[name='userID']").val(data.data.userID);
                $("input[name='rankType']").val(data.data.rankType);
                $("input[name='productID']").val(data.data.productID);
                $("input[name='specInfo']").val(data.data.specInfo);
                $("input[name='price']").val(data.data.price);
                $("input[name='number']").val(data.data.number);
                $("input[name='ptotal']").val(data.data.ptotal);
                $("input[name='transType']").val(data.data.transType);
            }
        });
    }
    /*--------------------------------审批线下支付的状态（通过与不通过）---------------------------------------------*/
</script>

</@page.pageBase>